package com.xbongbong.saas.enums.dictionary;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.saas.constant.BasicConstant;
import lombok.Getter;

import java.util.Objects;

/**
 * 订货单收款状态
 *
 * @author wujian
 * @version v1.0
 * @date 2021/01/09 11:12
 * @since v1.0
 */
@Getter
public enum OrderPayMentStatusEnum {
    //待结算
    PENDING_SETTLEMENT("1","enum.orderPaymentStatus.alias.pending_settlement","pendingSettlement"),
    //未收款
    UNCOLLECTED("2","enum.orderPaymentStatus.alias.uncollected","uncollected"),
    //部分收款
    PARTIAL_RECEIPTS("3", "enum.orderPaymentStatus.alias.partial_receipts","partialReceipts"),
    //已收款
    RECEIPT_FUND("4","enum.orderPaymentStatus.alias.receipt_fund","receiptFund"),

    UNKNOWN("404",  "enum.orderPaymentStatus.alias.unknown","unKnown"),
    ;

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    private String code;
    private String name;
    private String alias;

    OrderPayMentStatusEnum(String code, String name, String alias) {
        this.code = code;
        this.name = name;
        this.alias = alias;
    }

    /**
     * 根据订货单(合同)的未收金额与订货单(合同)金额的情况，得到其收款状态
     * @param amount 订货单(合同)金额
     * @param unFinishAmount 订货单(合同)未收金额
     * @return java.lang.String
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    public static String getOrderPayMentStatus(Double amount, double unFinishAmount){
        amount = Objects.isNull(amount) ? BasicConstant.ZERO_DOUBLE : amount;
        if (unFinishAmount > 0 && unFinishAmount < amount) {
            return PARTIAL_RECEIPTS.code;
        } else if (unFinishAmount == 0) {
            return RECEIPT_FUND.code;
        } else {
            return UNCOLLECTED.code;
        }
    }
}
